﻿package mortal.game.view.copy.groupCopy.view
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.display.*;
    import com.mui.manager.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import flash.utils.*;
    import mortal.common.*;
    import mortal.common.display.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.scene3D.layer3D.utils.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.mvc.core.*;

    public class GroupCopyMateRender extends GCellRenderer
    {
        private var _sgroupPlayer:SGroupPlayer;
        private var _bg:ScaleBitmap;
        private var _avatar:GImageBitmap;
        private var _avatarSp:ToolTipSprite;
        private var _state:GBitmap;
        private var _captainIcon:GBitmap;
        private var _name:GTextFiled;
        private var _levelAndCareer:GTextFiled;
        private var _combat:GTextFiled;
        private var _leftNum:GTextFiled;
        private var _avatarBg:GBitmap;
        private var _btnOper:GButton;
        private var _expTips:GTextFiled;

        public function GroupCopyMateRender()
        {
            return;
        }// end function

        override protected function initSkin() : void
        {
            var _loc_1:* = GlobalClass.getBitmap(BitmapDataConst.AlphaBMD);
            var _loc_2:* = ResourceConst.getScaleBitmap(ImagesConst.selectedBg);
            this.setStyle("downSkin", _loc_2);
            this.setStyle("overSkin", _loc_2);
            this.setStyle("upSkin", _loc_1);
            this.setStyle("selectedDownSkin", _loc_2);
            this.setStyle("selectedOverSkin", _loc_2);
            this.setStyle("selectedUpSkin", _loc_2);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            var _loc_1:* = GlobalStyle.textFormatBai;
            _loc_1.size = 14;
            this._bg = UIFactory.bg(2, 2, 455, 42, this, ImagesConst.MinigBg);
            this._avatarBg = UIFactory.gBitmap(ImagesConst.FriendHeadBg, 20, 2, this);
            this._captainIcon = UIFactory.gBitmap(ImagesConst.SmallCatain, 75, 10, this);
            this._name = UIFactory.gTextField("", 135, 0, 100, 30, this, _loc_1);
            this._combat = UIFactory.gTextField("", 135, 20, 120, 30, this, _loc_1);
            this._levelAndCareer = UIFactory.gTextField("", 280, 0, 100, 30, this, _loc_1);
            this._leftNum = UIFactory.gTextField("", 280, 20, 100, 30, this, _loc_1);
            this._avatarSp = UICompomentPool.getUICompoment(ToolTipSprite);
            this.addChild(this._avatarSp);
            this._avatar = UIFactory.gImageBitmap("", 22, 4, this._avatarSp);
            this._state = UIFactory.gBitmap(ImagesConst.Offline, 24, 10, this);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._bg.dispose(param1);
            this._bg = null;
            this._captainIcon.dispose(param1);
            this._captainIcon = null;
            this._avatar.dispose(param1);
            this._avatar = null;
            this._name.dispose(param1);
            this._name = null;
            this._levelAndCareer.dispose(param1);
            this._levelAndCareer = null;
            this._combat.dispose(param1);
            this._combat = null;
            this._leftNum.dispose(param1);
            this._leftNum = null;
            this._avatarSp.dispose(param1);
            this._avatarSp = null;
            this._state.dispose(param1);
            this._state = null;
            this._avatarBg.dispose(param1);
            this._avatarBg = null;
            if (this._expTips)
            {
                this._expTips.dispose(param1);
                this._expTips = null;
            }
            this._sgroupPlayer = null;
            this.clearOperBtn();
            super.disposeImpl(param1);
            return;
        }// end function

        private function updateOperBtnLabel() : void
        {
            if (EntityUtil.isSelf(this._sgroupPlayer.player.entityId))
            {
                this.addOperBtn(Language.getString(35231));
            }
            else if (Cache.instance.group.isCaptain)
            {
                this.addOperBtn(Language.getString(35232));
            }
            else
            {
                this.clearOperBtn();
            }
            return;
        }// end function

        private function addOperBtn(param1:String) : void
        {
            if (this._btnOper == null)
            {
                this._btnOper = UIFactory.gButton("", 394, 12, 49, 22, this);
            }
            this._btnOper.label = param1;
            this._btnOper.drawNow();
            this._btnOper.configEventListener(MouseEvent.CLICK, this.groupOperHandler);
            return;
        }// end function

        private function clearOperBtn() : void
        {
            if (this._btnOper)
            {
                this._btnOper.dispose();
                this._btnOper = null;
            }
            return;
        }// end function

        private function groupOperHandler(event:MouseEvent) : void
        {
            var _loc_2:* = event.currentTarget as GButton;
            if (_loc_2.label == Language.getString(35231))
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.GroupLeave));
            }
            else if (_loc_2.label == Language.getString(35232))
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.GroupKickOut, this._sgroupPlayer.player.entityId));
            }
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            var _loc_5:* = undefined;
            var _loc_6:GTextFormat = null;
            super.data = param1;
            if (!param1.data)
            {
                this._avatar.bitmapData = null;
                this._captainIcon.bitmapData = null;
                this._state.bitmapData = null;
                this._name.text = "";
                this._combat.text = "";
                this._levelAndCareer.text = "";
                this._leftNum.text = "";
                this._avatarBg.visible = false;
                this.clearOperBtn();
                if (this._expTips == null)
                {
                    _loc_6 = GlobalStyle.textFormatHuang2.center();
                    _loc_6.size = 14;
                    this._expTips = UIFactory.gTextField("", 154, 10, 150, 25, this, _loc_6);
                    this._expTips.mouseEnabled = false;
                    this._expTips.text = (param1.index + 1) + Language.getString(35233) + (param1.index + 1) * 5 + "%";
                }
                return;
            }
            if (this._expTips)
            {
                this._expTips.dispose();
                this._expTips = null;
            }
            this._sgroupPlayer = param1.data;
            var _loc_2:* = this._sgroupPlayer.player;
            this._avatar.imgUrl = AvatarUtil.getPlayerAvatarUrl(_loc_2.career, _loc_2.sex, AvatarUtil.Small);
            this._name.text = _loc_2.name;
            this._levelAndCareer.htmlText = "<font color=\'#BBD3F9\'>Lv." + _loc_2.level + "</font> · " + GameDefConfig.instance.getCarrer(_loc_2.career);
            this._combat.text = Language.getString(35234) + _loc_2.combat.toString();
            this._avatarBg.visible = true;
            var _loc_3:* = CopyConfig.instance.getCopyInfoByCode(Cache.instance.group.sgroup.copyCode);
            this._leftNum.htmlText = Language.getString(35235) + "<font color=\'#1ccc31\'>1/" + _loc_3.dayNum + "</font>";
            var _loc_4:* = Cache.instance.group.sgroup.copyNums;
            for (_loc_5 in _loc_4)
            {
                
                if (EntityUtil.equal(_loc_5 as SEntityId, _loc_2.entityId))
                {
                    this._leftNum.htmlText = Language.getString(35235) + "<font color=\'#1ccc31\'>" + Cache.instance.group.sgroup.copyNums[_loc_5] + "/" + _loc_3.dayNum + "</font>";
                    break;
                }
            }
            if (!Cache.instance.group.isCaptainById(_loc_2.entityId))
            {
                this._captainIcon.visible = false;
            }
            else
            {
                this._captainIcon.visible = true;
            }
            if (_loc_2.online)
            {
                this._avatarSp.filters = [];
                this._state.visible = false;
            }
            else
            {
                this._avatarSp.filters = [FilterConst.colorFilter2];
                this._state.visible = true;
            }
            this.updateOperBtnLabel();
            return;
        }// end function

    }
}
